<html>
<head><meta charset="utf-8"><title>value::AssocType and value::ASSOC_CONST · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html">value::AssocType and value::ASSOC_CONST</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231702959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231702959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231702959">(Mar 24 2021 at 20:27)</a>:</h4>
<p>Would it potentially be feasible to make associated values and associated constants available via values, not just via types?</p>



<a name="231702996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231702996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231702996">(Mar 24 2021 at 20:27)</a>:</h4>
<p>Simple (non-motivating) example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kt">u32</span> <span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"></span>
<span class="fm">dbg!</span><span class="p">(</span><span class="n">x</span>::<span class="n">MAX</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="231703250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231703250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231703250">(Mar 24 2021 at 20:29)</a>:</h4>
<p>This has more value for associated types, in particular. This would be a generalized solution for things like <code>some_function::Output</code>.</p>



<a name="231703261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231703261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231703261">(Mar 24 2021 at 20:29)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="231703271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231703271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231703271">(Mar 24 2021 at 20:29)</a>:</h4>
<p>aren't they different namespaces? i.e. you could have <code>mod x</code> that's still accessible despite the local <code>x</code></p>



<a name="231750460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231750460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231750460">(Mar 25 2021 at 05:41)</a>:</h4>
<p>maybe another flavor of qualified paths, like  <code>&lt;typeof(x)&gt;::MAX</code> ?</p>



<a name="231917775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231917775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231917775">(Mar 26 2021 at 05:37)</a>:</h4>
<p>why would you want that?</p>



<a name="231979531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231979531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231979531">(Mar 26 2021 at 15:02)</a>:</h4>
<blockquote>
<p>This has more value for associated types, in particular. This would be a generalized solution for things like <code>some_function::Output</code>.</p>
</blockquote>



<a name="231997658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231997658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231997658">(Mar 26 2021 at 16:50)</a>:</h4>
<p>maybe <code>{foo}::ETC</code> to give it a value context?</p>



<a name="231998059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/231998059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#231998059">(Mar 26 2021 at 16:52)</a>:</h4>
<p>If that's needed to disambiguate.</p>



<a name="232461656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/232461656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#232461656">(Mar 30 2021 at 17:06)</a>:</h4>
<p>This definitely seems to me more like <code>typeof</code>.</p>



<a name="232476531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/value%3A%3AAssocType%20and%20value%3A%3AASSOC_CONST/near/232476531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/value.3A.3AAssocType.20and.20value.3A.3AASSOC_CONST.html#232476531">(Mar 30 2021 at 18:45)</a>:</h4>
<p>Modulo syntax, supporting either feature leads to featuring the other one:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">{</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">}</span>::<span class="n">ASSOC</span><span class="w"></span>
<span class="c1">// can be implemented with</span>
<span class="o">&lt;</span><span class="kr">typeof</span><span class="p">(</span><span class="n">foo</span><span class="p">)</span><span class="o">&gt;</span>::<span class="n">ASSOC</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kr">typeof</span><span class="p">(</span><span class="n">EXPR</span><span class="p">)</span><span class="w"></span>
<span class="c1">// can be implemented with</span>
<span class="k">trait</span><span class="w"> </span><span class="n">GetTypeOf</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">TypeOf</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">// Or use a helper wrapper type with an inherent assoc type, once supported</span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="w"> </span><span class="n">GetTypeOf</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">TypeOf</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">{</span><span class="w"> </span><span class="n">EXPR</span><span class="w"> </span><span class="p">}</span>::<span class="n">TypeOf</span><span class="w"></span>
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>